﻿namespace zyn_hy_login
{
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Configuration;

    public class DBCommon
    {
        public static string strConnectstring = ConfigurationSettings.AppSettings["ConnectionString"];

        public static void excuteSql(string strSql)
        {
            SqlConnection connection = new SqlConnection();
            connection.ConnectionString = strConnectstring;
            SqlCommand command = new SqlCommand();
            command.CommandType = CommandType.Text;
            command.CommandText = strSql;
            command.Connection = connection;
            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }

        public static int excuteSqlCount(string strSql)
        {
            SqlConnection connection = new SqlConnection();
            connection.ConnectionString = strConnectstring;
            SqlCommand command = new SqlCommand();
            command.CommandType = CommandType.Text;
            command.CommandText = strSql;
            command.Connection = connection;
            SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = command;
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet);
            int count = dataSet.Tables[0].Rows.Count;
            dataSet.Clear();
            connection.Close();
            return count;
        }

        public static DataSet getDataBySql(string strSql)
        {
            SqlConnection connection = new SqlConnection();
            connection.ConnectionString = strConnectstring;
            SqlCommand command = new SqlCommand();
            command.CommandType = CommandType.Text;
            command.CommandText = strSql;
            command.Connection = connection;
            SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = command;
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet);
            return dataSet;
        }

        public SqlDataReader getDataReadBySql(string strSql)
        {
            SqlConnection connection = new SqlConnection();
            connection.ConnectionString = strConnectstring;
            SqlCommand command = new SqlCommand();
            command.CommandType = CommandType.Text;
            command.CommandText = strSql;
            command.Connection = connection;
            connection.Open();
            return command.ExecuteReader(CommandBehavior.CloseConnection);
        }
    }
}

